package Test;
import java.lang.Integer;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Car[] mycar = new Car[3];
        mycar[0] = new Car("Toyota", "Camry", "黑色", 100.0, true);
        mycar[1] = new Car("Honda", "Civic", "红色", 80.0, true);
        mycar[2] = new Car("Ford", "Focus", "银色", 90.0, true);
        int k;
        int member1 = 0;
        int count1 = 0;
        Scanner sc = new Scanner(System.in);
        do {
           do {
               System.out.println("【汽车租贷系统】");
               System.out.println("租车还是还车(0退出)");
               System.out.print("请输入:");
               String rentornot = sc.next();
               if (rentornot.equals("还车")) {
                   for (Car car : mycar) {
                       if (!car.isrent) {
                           count1++;
                           //System.out.println((j + 1) + ". " + mycar[j].brand + " " + mycar[j].type + " " + mycar[j].color + " " + mycar[j].price + "/天");
                       }
                   }
                   if (count1 == 3) {
                       System.out.println("不好意思,没有车辆可还,谢谢下次惠顾!");
                       break;
                   }
                   System.out.println("可还车辆:");
                   for (int j = 0; j < mycar.length; j++) {
                       if (!mycar[j].isrent) {
                           System.out.println((j + 1) + ". " + mycar[j].brand + " " + mycar[j].type + " " + mycar[j].color + " " + mycar[j].price + "/天");
                       }
                   }
                   System.out.print("输入你要还的车的编号(输入0退出):");
                   member1 = sc.nextInt();
                   if (member1 != 0) {
                       if (!mycar[member1 - 1].isrent) {
                           k = member1 - 1;
                           mycar[k].isrent = true;
                           System.out.println("你还了一辆" + "  " + mycar[k].color + "  " + mycar[k].type);
                       }
                   }

               }
               else if(rentornot.equals("租车"))
               {
                   int count2 = 0;
                   for (Car car : mycar) {
                       if (car.isrent) {
                           count2++;
                           //System.out.println((i + 1) + ". " + mycar[i].brand + " " + mycar[i].type + " " + mycar[i].color + " " + mycar[i].price + "/天");
                       }
                   }
                   if (count2 == 0) {
                       System.out.println("不好意思，没有车辆可租了,谢谢下次会顾!");
                       break;
                   }
                   System.out.println("可租车俩：");
                   for (int i = 0; i < mycar.length; i++) {
                       if (mycar[i].isrent) {
                           System.out.println((i + 1) + ". " + mycar[i].brand + " " + mycar[i].type + " " + mycar[i].color + " " + mycar[i].price + "/天");
                       }
                   }
                   System.out.print("输入你要租的车的编号(输入0退出):");
                   Rental2 r1 = new Rental2();
                   member1 = sc.nextInt();
                   if (member1 != 0) {
                       if (mycar[member1 - 1].isrent) {
                           k = member1 - 1;
                           r1.setRentmember(member1);
                           mycar[k].isrent = false;
                           System.out.print("输入你要租的天数:");
                           int n = sc.nextInt();
                           r1.setRentday(n);
                           r1.setRentmoney(r1.rentday * mycar[k].price);
                           System.out.println("你租了一辆" + "  " + mycar[k].color + "  " + mycar[k].type + "  " + "共" + "  " + r1.rentday + "天");
                           System.out.println("总租金:" + r1.rentmoney);
                       }
                   }
               }
               else
               {
                   member1 = Integer.parseInt(rentornot);
               }
           }while(member1!=0);
        }while (member1 != 0) ;
    }
}



